//
//  ListGridCell.m
//  商城
//
//  Created by runone02 on 2018/9/17.
//  Copyright © 2018年 liqiyun. All rights reserved.
//

#import "ListGridCell.h"
#import "DCRecommendItem.h"
#import <UIImageView+WebCache.h>

@interface ListGridCell ()

/* 商品图片 */
@property (strong , nonatomic)UIImageView *gridImageView;
/** 名称*/
@property (nonatomic,strong) UILabel *namelabel;
/** 时间*/
@property (nonatomic,strong) UILabel *timelabel;
/** 道路名称*/
@property (nonatomic,strong) UILabel *roadNameLabel;
/** 桩号*/
@property (nonatomic,strong) UILabel *mileageLabel;
/** 方向*/
@property (nonatomic,strong) UILabel *directionLabel;
/** 状态*/
@property (nonatomic,strong) UILabel *stateLabel;
/** */
@property (nonatomic,strong) UIImageView *arrowImage;
@end

@implementation ListGridCell

#pragma mark - Intial
- (instancetype)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    if (self) {
        
        [self setUpUI];
    }
    return self;
}

#pragma mark - UI
- (void)setUpUI{
    UIView *bgView = [[UIView alloc]init];
    bgView.backgroundColor = [UIColor whiteColor];
    [self addSubview:bgView];
    
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.mas_equalTo(self);
    }];
    
    //图片
    _gridImageView = [[UIImageView alloc] init];
    _gridImageView.contentMode = UIViewContentModeScaleAspectFill;
    _gridImageView.clipsToBounds = YES;
    [bgView addSubview:_gridImageView];
    
    [self.gridImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(bgView);
        make.left.mas_equalTo(bgView).with.offset(10);
        make.width.height.mas_equalTo(60);
    }];
    
    //名称
    self.namelabel = [[UILabel alloc]init];
    self.namelabel.textColor = [UIColor blackColor];
    self.namelabel.font = TITLE_FONT(28);
    [bgView addSubview:self.namelabel];
    [self.namelabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.gridImageView);
        make.left.mas_equalTo(self.gridImageView.mas_right).with.offset(10);
        make.width.mas_equalTo(SCREEN_WIDTH/3);
    }];
    
    //时间
    self.timelabel = [[UILabel alloc]init];
    self.timelabel.textColor = [UIColor blackColor];
    self.timelabel.font = TITLE_FONT(28);
    [bgView addSubview:self.timelabel];
    [self.timelabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.gridImageView);
        make.left.mas_equalTo(self.namelabel.mas_right).with.offset(10);
        make.right.mas_equalTo(bgView).with.offset(-5);
    }];

    //道路名称
    self.roadNameLabel = [[UILabel alloc]init];
    self.roadNameLabel.textColor = [UIColor blackColor];
    self.roadNameLabel.font = TITLE_FONT(28);
    [bgView addSubview:self.roadNameLabel];
    [self.roadNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.gridImageView);
        make.left.mas_equalTo(self.gridImageView.mas_right).with.offset(10);
        make.width.mas_equalTo(SCREEN_WIDTH/6);
    }];

    //桩号
    self.mileageLabel = [[UILabel alloc]init];
    self.mileageLabel.textColor = [UIColor blackColor];
    self.mileageLabel.text = @"桩号";
    self.mileageLabel.font = TITLE_FONT(28);
    [bgView addSubview:self.mileageLabel];
    [self.mileageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.gridImageView);
        make.left.mas_equalTo(self.roadNameLabel.mas_right).with.offset(10);
        make.width.mas_equalTo(SCREEN_WIDTH/6);
    }];
//方向
    self.directionLabel = [[UILabel alloc]init];
    self.directionLabel.textColor = [UIColor blackColor];
    self.directionLabel.text = @"方向";
    self.directionLabel.font = TITLE_FONT(28);
    [bgView addSubview:self.directionLabel];
    [self.directionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.gridImageView);
        make.left.mas_equalTo(self.mileageLabel.mas_right).with.offset(10);
        make.width.mas_equalTo(SCREEN_WIDTH/6);
    }];
//箭头
    self.arrowImage = [[UIImageView alloc]init];
    self.arrowImage.backgroundColor = [UIColor redColor];
    [bgView addSubview:self.arrowImage];
    [self.arrowImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.roadNameLabel);
        make.right.mas_equalTo(bgView).with.offset(-5);
        make.width.height.mas_equalTo(20);
    }];
//
    self.stateLabel = [[UILabel alloc]init];
    self.stateLabel.textColor = [UIColor blackColor];
    self.stateLabel.text = @"状态";
    self.stateLabel.font = TITLE_FONT(28);
    [bgView addSubview:self.stateLabel];
    [self.stateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.gridImageView);
        make.left.mas_equalTo(self.directionLabel.mas_right).with.offset(5);
        make.right.mas_equalTo(self.arrowImage.mas_left).with.offset(-5);
    }];

    UIView *lineView = [[UIView alloc]init];
    lineView.backgroundColor = [UIColor lightGrayColor];
    [bgView addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(bgView);
        make.left.right.mas_equalTo(bgView);
        make.height.mas_equalTo(1);
    }];
}



#pragma mark - Setter Getter Methods
- (void)setYouSelectItem:(DCRecommendItem *)youSelectItem{
    _youSelectItem = youSelectItem;
    [_gridImageView sd_setImageWithURL:[NSURL URLWithString:youSelectItem.image_url]];
    _namelabel.text = youSelectItem.main_title;
    _timelabel.text = youSelectItem.goods_title;
    _roadNameLabel.text = youSelectItem.price;
    _mileageLabel.text = youSelectItem.stock;
    _directionLabel.text = youSelectItem.stock;
    _stateLabel.text = youSelectItem.stock;
}

@end
